<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html>
<html>
    <meta charset="UTF-8" />
    <title>拼团活动管理</title>
    <head>
        <style>
            body{
                margin: 0;
                font-family: 'Segoe UI',Tahoma,Geneva,Verdana,sans-serif;
                background-color: #f5f7fa;
            }

            .sidebar {
                width: 220px;
                background: #5a4e9a;
                color: white;
                height: 100vh;
                position: fixed;
                display: flex;
                flex-direction: column;
            }
            .sidebar a{
                color: white;
                text-decoration: none;
                padding: 15px 20px;
                display: block;
                border-left: 4px solid transparent;
            }
            .sidebar a:hover,
            .sidebar a.active{
                background: #7a6ccc;
                border-left: 4px solid #d3c9ff;
            }

            .header {
                margin-left: 220px; height: 60px; background: white; box-shadow: 0 2px 8px rgb(0 0 0 / 0.1);
                display: flex; align-items: center; justify-content: flex-end; padding: 0 20px;
            }
            .header a {
                color: #5a4e9a; text-decoration: none; font-weight: 600;
            }
            .content {
                margin-left: 220px; padding: 20px; min-height: calc(100vh - 60px);
            }
            h1 { color: #5a4e9a; }
            button {
                background: linear-gradient(135deg, #a188ff, #7a6ccc);
                border: none; color: white; padding: 6px 12px; border-radius: 6px;
                cursor: pointer;
                transition: background 0.3s ease;
            }
            button:hover {
                background: linear-gradient(135deg, #c2b7ff, #9587d7);
            }
            input[type=text], input[type=number], select {
                padding: 8px 10px;
                border-radius: 6px;
                border: 1px solid #ccc;
                width: 100%;
                box-sizing: border-box;
                margin-top: 6px;
                margin-bottom: 16px;
            }
            .form-group {
                margin-bottom: 20px;
            }
            label {
                font-weight: 600; color: #555;
            }
        </style>
    </head>
    <body>
    <div class="sidebar">
        <h2 style="text-align:center; margin:20px 0; font-weight:700;">后台管理</h2>
        <a href="${pageContext.request.contextPath}/admin/product/list" class="<%= request.getRequestURI().contains("/admin/product") ? "active" : "" %>">商品管理</a>
        <a href="${pageContext.request.contextPath}/admin/category/list" class="<%= request.getRequestURI().contains("/admin/category") ? "active" : "" %>">分类管理</a>
        <a href="${pageContext.request.contextPath}/admin/group/list" class="<%= request.getRequestURI().contains("/admin/group") ? "active" : "" %>">拼团活动管理</a>
        <a href="${pageContext.request.contextPath}/admin/order/list" class="<%= request.getRequestURI().contains("/admin/order") ? "active" : "" %>">订单管理</a>
    </div>
    <div class="header">
        <a href="${pageContext.request.contextPath}/front/login">退出登录</a>
    </div>
    <div class="content">
        <h1>${group != null ? "编辑拼团活动" :"新增拼团活动"}</h1>
        <form action="${pageContext.request.contextPath}/admin/group/${group != null ? 'edit' :'add'}" method="post">
            <c:if test="${group != null}">
                <input type="hidden" name="id" value="${group.id}" />
            </c:if>

            <select name="productId" required>
                <c:forEach var="p" items="${productList}">
                    <option value="${p.id}" ${group != null && group.product.id == p.id ? 'selected' : ''}>${p.name}</option>
                </c:forEach>
            </select>

            <div class="form-group">
                <label>开始时间</label>
                <input type="datetime-local" name="startTime" value="${group.startTime}" required />
            </div>

            <div class="form-group">
                <label>结束时间</label>
                <input type="datetime-local" name="endTime" value="${group.endTime}" required />
            </div>

            <div class="form-group">
                <label>拼团人数</label>
                <input type="number" name="groupSize" value="${group.groupSize}" required />
            </div>

            <div class="form-group">
                <label>拼团价格</label>
                <input type="number" step="0.01" name="groupPrice" value="${group.groupPrice}" required />
            </div>

            <div class="actions">
                <button type="submit">保存</button>
                <a href="${pageContext.request.contextPath}/admin/group/list">
                    <button type="button">取消</button>
                </a>
            </div>
        </form>
    </div>
    </body>
</html>